package com.luci.security.support;

import com.luci.security.result.JwtUser;
import com.luci.security.result.LoginException;
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;

/**
 * 登录支持相关接口
 *
 * @author yuyanan
 * @version 1.0
 * @date 18-11-2
 */
public interface ILogin<T extends ILoginBo> {

    /**
     * <pre>
     *     登录参数类class 必须是ILoginBo接口类的实现类
     * </pre>
     * @return Class
     */
    Class<T> getLoginBoClass();

    /**
     * <pre>
     *     登陆认证2:登录实现
     * </pre>
     *
     * @param t 登录参数
     * @throws LoginException 登录失败异常
     * @return JwtUser 会根据此对象会生成jwt token 此处只要赋值 [username用户名 roles角色] 即可
     */
    JwtUser login(T t) throws LoginException;

    /**
     * 登陆认证3:登录成功
     * <pre>
     *     登录成功
     * </pre>
     * @param request HttpServletRequest
     * @param response HttpServletResponse
     * @param authentication Authentication
     */
    void loginSuccess(HttpServletRequest request, HttpServletResponse response,
                                              Authentication authentication) throws IOException;

    /**
     * 登陆认证4:登录失败
     * <pre>
     *      登录失败
     * </pre>
     * @param request HttpServletRequest
     * @param response HttpServletResponse
     * @param exception AuthenticationException
     */
    void loginFail(HttpServletRequest request, HttpServletResponse response,
                                           AuthenticationException exception) throws IOException;

}
